package cn.hlife.com.hlfhaemocyte.bluetooth;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.Arrays;

import cn.hlife.com.bluetooth20_connect.lib.BluetoothService;
import cn.hlife.com.hlfhaemocyte.bean.MeasureEntity;
import cn.hlife.com.hlfhaemocyte.utils.HaemocyteApplication;
import cn.hlife.com.hlfhaemocyte.utils.PrintUtils;
import cn.hlife.com.hlfhaemocyte.utils.RDPrinterInterface;
import cn.hlife.com.hlfhaemocyte.utils.SharedPreferencesUtils;

/**
 * Created by Administrator on 2017/7/27.
 */

public class BluetoothPrint {

    private DecimalFormat decimalFormat = new DecimalFormat("0.0");


    BluetoothService bluetoothService;

    private void BluetoothPrint() {

    }

    public static BluetoothPrint getInstance() {
        return BluetoothPrintHelp.bluetoothPrint;
    }

    static class BluetoothPrintHelp {
        static BluetoothPrint bluetoothPrint = new BluetoothPrint();
    }

    public void setBluetoothServiceInstance(BluetoothService bluetoothService) {
        this.bluetoothService = bluetoothService;
    }

    public BluetoothService getBluetoothService() {
        return bluetoothService;
    }

    public static void setOutputStream(OutputStream outputStream) {
        PrintUtils.outputStream = outputStream;
    }

    public void PrintBitmap(Bitmap bitmap) throws IOException {
        bluetoothService.write(RDPrinterInterface.MIND);//居中
        RDPrinterInterface mRDPrinterInterface = RDPrinterInterface.getInstance();
        byte[] add = RDPrinterInterface.getByteArray(0x00);
        int[] sourceData = mRDPrinterInterface.getBitmapData(bitmap);
        byte[] data = RDPrinterInterface.getByteArray(sourceData);
        LineSpace_SET(add[0], bluetoothService);//行间距
        int sendLen = bitmap.getWidth();
        byte[] ImageCMD = mRDPrinterInterface.getImageCmd(RDPrinterInterface.IMAGECMD, sendLen);
        for (int i = 0; i < data.length / sendLen; i++) {
            byte[] temp = Arrays.copyOfRange(data, i * sendLen, (i + 1) * sendLen);
            byte[] stemp = RDPrinterInterface.concat(temp, RDPrinterInterface.WRAP_PRINT);
            byte[] printData = RDPrinterInterface.concat(ImageCMD, stemp);
            Write(printData, bluetoothService);
        }
    }

    private void Write(byte[] command, BluetoothService mService) throws IOException {
        int maxLenth = 1024;
        int count = command.length / maxLenth;
        byte[] buffer = null;
        for (int i = 0; i <= count; i++) {
            if (i < count) {
                buffer = Arrays.copyOfRange(command, i * maxLenth, (i + 1)
                        * maxLenth);
            } else {
                buffer = Arrays.copyOfRange(command, i * maxLenth,
                        command.length);
            }
            mService.write(buffer);
        }
    }

    //打印字体／图片行间距设置 0x00～0xFF
    //打印图片设置为0x0
    //打印文字参考设置为0x5
    public void LineSpace_SET(byte sp, BluetoothService mService) throws IOException {
        byte[] PRINT_LINESPACE_SET = new byte[3];
        System.arraycopy(RDPrinterInterface.PRINT_LINESPACE, 0, PRINT_LINESPACE_SET, 0, RDPrinterInterface.PRINT_LINESPACE.length);
        PRINT_LINESPACE_SET[2] = sp;
        mService.write(PRINT_LINESPACE_SET);
    }

    public Bitmap createReportBitmap(MeasureEntity measureEntity) {
        int landscape = 130, startscape = 20;//横向的间隔
        int verticalHigh = 25, startvertical = 20;//纵向间隔
        String testStr = "检验报告单";
        Bitmap bitmap = Bitmap.createBitmap(930, 384, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawColor(Color.parseColor("#FFFFFFFF"));
        TextPaint textPaint = new TextPaint();
        textPaint.setAntiAlias(true);
        textPaint.setTextSize(20.0F);
        canvas.drawText(testStr, 400, startvertical, textPaint);
        textPaint.setTextSize(16.0F);
        textPaint.setStrokeWidth((float) 0.5);
        Typeface mTf = Typeface.createFromAsset(HaemocyteApplication.getInstance().getAssets(), "fonts/苹果iOS9苹方纤细体UltraLight_50868_S60SC_C.ttf");
        textPaint.setTypeface(mTf);
        String reportRefernce = SharedPreferencesUtils.getInstance().getReportRefernce(HaemocyteApplication.getInstance());
        Bitmap bm = null;
        JSONObject jsonObject = null;
        try {

            jsonObject = new JSONObject(reportRefernce);
            testStr = "姓     名:" + measureEntity.getMUserName();
            canvas.drawText(testStr, startscape, verticalHigh + startvertical, textPaint);
            testStr = "性     别:" + measureEntity.getUserSex();
            canvas.drawText(testStr, startscape + landscape, verticalHigh + startvertical, textPaint);
            testStr = "病床号:" + measureEntity.getMHospitalBedNumber();
            canvas.drawText(testStr, startscape + landscape * 2 - 10, verticalHigh + startvertical, textPaint);
            testStr = "科     室:" + measureEntity.getMSection();
            canvas.drawText(testStr, startscape + landscape * 3 - 30 - 20, verticalHigh + startvertical, textPaint);
            testStr = "病 历 号:" + measureEntity.getMMedicalNumber();
            ;
            canvas.drawText(testStr, startscape + landscape * 4 + 20, verticalHigh + startvertical, textPaint);
            testStr = "样 本 号:" + measureEntity.getMSampleID();
            canvas.drawText(testStr, startscape + landscape * 5 + 50, verticalHigh + startvertical, textPaint);
            /**--------------------------------------------------------------------------------------------------------------*/
            testStr = "送检标本:" + measureEntity.getMSpecimen();
            canvas.drawText(testStr, startscape, verticalHigh * 2 + startvertical, textPaint);
            testStr = "送检医生:" + measureEntity.getMDoctor();
            canvas.drawText(testStr, startscape + landscape, verticalHigh * 2 + startvertical, textPaint);

            testStr = "年   龄:" + measureEntity.getMAge();
            canvas.drawText(testStr, startscape + landscape * 2 - 10, verticalHigh * 2 + startvertical, textPaint);
            testStr = "送检时间:" + measureEntity.getMTime();
            canvas.drawText(testStr, startscape + landscape * 3 - 30 - 20, verticalHigh * 2 + startvertical, textPaint);
            testStr = "临床诊断:" + measureEntity.getMClinicalDiagnosis();
            canvas.drawText(testStr, startscape + landscape * 4 + 20, verticalHigh * 2 + startvertical, textPaint);
            testStr = "备    注:" + measureEntity.getMRemark();
            canvas.drawText(testStr, startscape + landscape * 5 + 50, verticalHigh * 2 + startvertical, textPaint);
            testStr = "-----------------------------------------------------------------------------------------";
            canvas.drawText(testStr, 20, verticalHigh * 3 + startvertical - 10, textPaint);
            /**--------------------------------------------------------------------------------------------------------------*/

            testStr = "项目";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 3 + startvertical, textPaint);
            testStr = "结果";
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 3 + startvertical, textPaint);
            testStr = "单位";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 3 + startvertical, textPaint);
            testStr = "参考值";
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 3 + startvertical, textPaint);


            testStr = "WBC 白细胞";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 4 + startvertical, textPaint);
            if (measureEntity.getWBCNUmber() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getWBCNUmber());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 4 + startvertical, textPaint);
            testStr = "x10" + "⁹" + "/L";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 4 + startvertical, textPaint);
            testStr = jsonObject.getString("WBC");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 4 + startvertical, textPaint);

            testStr = "LYM# 淋巴细胞数";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 5 + startvertical, textPaint);
            if (measureEntity.getLymNumber_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getLymNumber_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 5 + startvertical, textPaint);
            testStr = "x10" + "⁹" + "/L";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 5 + startvertical, textPaint);
            testStr = jsonObject.getString("LYM");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 5 + startvertical, textPaint);

            testStr = "MON# 单核细胞数";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 6 + startvertical, textPaint);
            if (measureEntity.getMidNumber_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getMidNumber_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 6 + startvertical, textPaint);
            testStr = "x10" + "⁹" + "/L";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 6 + startvertical, textPaint);
            testStr = jsonObject.getString("MON");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 6 + startvertical, textPaint);


            testStr = "GRA# 粒细胞数";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 7 + startvertical, textPaint);
            if (measureEntity.getNeuNumber_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getNeuNumber_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 7 + startvertical, textPaint);
            testStr = "x10" + "⁹" + "/L";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 7 + startvertical, textPaint);
            testStr = jsonObject.getString("GRA");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 7 + startvertical, textPaint);


            testStr = "LYM% 淋巴细胞百分比";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 8 + startvertical, textPaint);
            if (measureEntity.getLymPercent_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getLymPercent_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 8 + startvertical, textPaint);
            testStr = "%";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 8 + startvertical, textPaint);
            testStr = jsonObject.getString("LYMP");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 8 + startvertical, textPaint);

            testStr = "MON% 单核细胞百分比";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 9 + startvertical, textPaint);
            if (measureEntity.getMidPercent_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getMidPercent_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 9 + startvertical, textPaint);
            testStr = "%";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 9 + startvertical, textPaint);
            testStr =jsonObject.getString("MONP") ;
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 9 + startvertical, textPaint);

            testStr = "GRA% 粒细胞百分比";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 10 + startvertical, textPaint);
            if (measureEntity.getNeuPercent_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getNeuPercent_Value());
            }

            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 10 + startvertical, textPaint);
            testStr = "%";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 10 + startvertical, textPaint);
            testStr = jsonObject.getString("GRAP");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 10 + startvertical, textPaint);

            testStr = "HGB 血红蛋白";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 11 + startvertical, textPaint);
            if (measureEntity.getHGB_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getHGB_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 11 + startvertical, textPaint);
            testStr = "g/L";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 11 + startvertical, textPaint);
            testStr = jsonObject.getString("HGB");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 11 + startvertical, textPaint);

            testStr = "MCH 平均血红蛋白含量";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 12 + startvertical, textPaint);
            if (measureEntity.getMCH_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getMCH_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 12 + startvertical, textPaint);
            testStr = "P/g";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 12 + startvertical, textPaint);
            testStr = jsonObject.getString("MCH");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 12 + startvertical, textPaint);

            testStr = "MCHC 平均血红蛋白浓度";
            canvas.drawText(testStr, startscape + 10, verticalHigh * 13 + startvertical, textPaint);
            if (measureEntity.getMCHC_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getMCHC_Value());
            }
            canvas.drawText(testStr, startscape + landscape + 100, verticalHigh * 13 + startvertical, textPaint);
            testStr = "g/L";
            canvas.drawText(testStr, startscape + landscape * 2 + 30, verticalHigh * 13 + startvertical, textPaint);
            testStr = jsonObject.getString("MCHC");
            canvas.drawText(testStr, startscape + landscape * 3 - 30, verticalHigh * 13 + startvertical, textPaint);
            testStr = "-----------------------------------------------------------------------------------------";
            canvas.drawText(testStr, 20, verticalHigh * 14 + startvertical - 10, textPaint);
            /**------------------------------------------------------------------------------------------------*/


            testStr = "项目";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 3 + startvertical, textPaint);
            testStr = "结果";
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 3 + startvertical, textPaint);
            testStr = "单位";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 3 + startvertical, textPaint);
            testStr = "参考值";
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 3 + startvertical, textPaint);

            testStr = "RBC 红细胞";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 4 + startvertical, textPaint);
            if (measureEntity.getRBCNumber() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getRBCNumber());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 4 + startvertical, textPaint);
            testStr = "x10¹²/L";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 4 + startvertical, textPaint);
            testStr = jsonObject.getString("RBC");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 4 + startvertical, textPaint);

            testStr = "MCV 平均红细胞体积";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 5 + startvertical, textPaint);
            if (measureEntity.getMCV_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getMCV_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 5 + startvertical, textPaint);
            testStr = "f/L";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 5 + startvertical, textPaint);
            testStr = jsonObject.getString("MCV");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 5 + startvertical, textPaint);

            testStr = "HCT 红细胞压积";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 6 + startvertical, textPaint);
            if (measureEntity.getHCT_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getHCT_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 6 + startvertical, textPaint);
            testStr = "%";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 6 + startvertical, textPaint);
            testStr = jsonObject.getString("HCT");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 6 + startvertical, textPaint);

            testStr = "RDWSD 红细胞分布宽度SD";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 7 + startvertical, textPaint);
            if (measureEntity.getRDWSD_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getRDWSD_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 7 + startvertical, textPaint);
            testStr = "f/L";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 7 + startvertical, textPaint);
            testStr = jsonObject.getString("PDWSD");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 7 + startvertical, textPaint);

            testStr = "RDWCV 红细胞分布宽度CV";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 8 + startvertical, textPaint);

            if (measureEntity.getRDWCV_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getRDWCV_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 8 + startvertical, textPaint);
            testStr = "%";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 8 + startvertical, textPaint);
            testStr = jsonObject.getString("PDWCV");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 8 + startvertical, textPaint);

            testStr = "PLT 血小板";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 9 + startvertical, textPaint);
            if (measureEntity.getPLTNumber() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getPLTNumber());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 9 + startvertical, textPaint);
            testStr = "x10⁹/L";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 9 + startvertical, textPaint);
            testStr =jsonObject.getString("PLT");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 9 + startvertical, textPaint);

            testStr = "PCT 血小板压积";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 10 + startvertical, textPaint);
            if (measureEntity.getPCT_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getPCT_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 10 + startvertical, textPaint);
            testStr = "%";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 10 + startvertical, textPaint);
            testStr = jsonObject.getString("PLTY");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 10 + startvertical, textPaint);

            testStr = "MPV 平均血小板体积";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 11 + startvertical, textPaint);
            if (measureEntity.getMPV_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getMPV_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 11 + startvertical, textPaint);
            testStr = "f/L";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 11 + startvertical, textPaint);
            testStr =jsonObject.getString("MPV");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 11 + startvertical, textPaint);

            testStr = "PDW 血小板分布宽度";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 12 + startvertical, textPaint);
            if (measureEntity.getPDW_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getPDW_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 12 + startvertical, textPaint);
            testStr = "f/L";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 12 + startvertical, textPaint);
            testStr = jsonObject.getString("PDW");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 12 + startvertical, textPaint);

            testStr = "P-LCR 大血小板比率";
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 13 + startvertical, textPaint);
            if (measureEntity.getPLCR_Value() < 0) {
                testStr = "0.0";
            } else {
                testStr = decimalFormat.format(measureEntity.getPLCR_Value());
            }
            canvas.drawText(testStr, startscape + landscape * 5 + 20, verticalHigh * 13 + startvertical, textPaint);
            testStr = "%";
            canvas.drawText(testStr, startscape + landscape * 4 + 210, verticalHigh * 13 + startvertical, textPaint);
            testStr = jsonObject.getString("PLCR");
            canvas.drawText(testStr, startscape + landscape * 5 + 150, verticalHigh * 13 + startvertical, textPaint);
            /**------------------------------------------------------------------------------------------------*/
            testStr = "此样本仅对此标本负责";
            canvas.drawText(testStr, startscape, verticalHigh * 14 + startvertical, textPaint);
            testStr = "检验员:" + measureEntity.getInspector();
            canvas.drawText(testStr, startscape + landscape * 3 - 30 + 100, verticalHigh * 14 + startvertical, textPaint);
            testStr = "复核员:" + measureEntity.getVerifyPerson();
            canvas.drawText(testStr, startscape + landscape * 5 + 50, verticalHigh * 14 + startvertical, textPaint);

            Matrix matrix = new Matrix();
            matrix.postScale(1f, 1f);
            matrix.postRotate(90);
            bm= Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                    bitmap.getHeight(), matrix, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bm;
    }
}
